package com.macllvm.whale;

import android.app.Application;
import android.content.Context;
import android.os.Environment;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkInfo.State;
import android.net.wifi.WifiManager;
import android.util.Log;
import java.io.File;
import com.macllvm.whale.sound.SoundPlayer;
import com.macllvm.whale.settings.SystemSettings;
import com.macllvm.whale.protocol.PacketPackager;
import com.macllvm.whale.protocol.ProtocolController;

public class WhaleApplication extends Application {
    private static final String TAG = "WhaleApplication";
    private Context context;
    private SystemSettings settings;
    public  static SoundPlayer mSoundPlayer;

    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        settings = new SystemSettings(context);
        mSoundPlayer = new SoundPlayer(context);
        PacketPackager.setSystemSettings(settings);
        ProtocolController.getInstance().setSystemSettings(settings);
    }


    public void checkStoragePath() {
        String appPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/WhaleIM";
        String downloadPath =  appPath + "/download";
        File f = new File(appPath);
        if(!f.exists()){
            f.mkdir();
        }

        f = new File(downloadPath);
        if(!f.exists()){
            f.mkdir();
        }
    }


    public boolean wifiIsAvailable() {
        WifiManager manager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
        int state = manager.getWifiState();
        if(state == WifiManager.WIFI_STATE_ENABLED){
            return true;
        }
        return false;
    }

    public SystemSettings getSystemSettings() {
        return settings;
    }

    public void loadSettings() {
        settings.loadSettings();
    }

}
